//
//  HNRegion.m
//  BestLearning
//
//  Created by 星道 on 17/5/16.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "HNRegion.h"
@implementation HNRegion

- (void)GetProvice
{
    NSData *JSONData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"shengfen" ofType:@"json"]];
    NSArray *dataArray = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingAllowFragments error:nil];
    NSMutableArray *Arr = [NSMutableArray array];
    for (NSDictionary *Dict in dataArray)
    {
        //创建省城区
        Provice *Model = [[Provice alloc] initWithDict:Dict];
        [Arr addObject:Model];
    }
    self.Provices = [Arr copy];
}

- (void)GetCityWithProvinceid:(NSInteger)Provinceid
{
    NSData *JSONData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"allcity" ofType:@"json"]];
    NSArray *dataArray = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingAllowFragments error:nil];
    NSMutableArray *Arr = [NSMutableArray array];
    for (NSDictionary *Dict in dataArray)
    {
        if (Provinceid == [Dict[@"provinceid"] integerValue])
        {
            City *Model = [[City alloc] initWithDict:Dict];
            [Arr addObject:Model];
        }
    }
    self.Cities = [Arr copy];
}

- (void)GetAreaWithCityid:(NSInteger)Cityid
{
    NSData *JSONData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"allarea" ofType:@"json"]];
    NSArray *dataArray = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingAllowFragments error:nil];
    NSMutableArray *Arr = [NSMutableArray array];
    for (NSDictionary *Dict in dataArray)
    {
        if (Cityid == [Dict[@"cityid"] integerValue])
        {
            Area *Model = [[Area alloc] initWithDict:Dict];
            [Arr addObject:Model];
        }
    }
    if (Arr.count <=0 )
    {
        Area *Model = [[Area alloc] init];
        Model.cityid = @(Cityid);
        Model.areaid = 0;
        Model.areaname = @"市辖区";
        Model.is_system = @0;
        [Arr addObject:Model];
    }
    self.Areas = [Arr copy];
}
- (NSArray<Provice *> *)Provices
{
    if (!_Provices)
    {
        NSData *JSONData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"shengfen" ofType:@"json"]];
        NSArray *dataArray = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingAllowFragments error:nil];
        NSMutableArray *Arr = [NSMutableArray array];
        for (NSDictionary *Dict in dataArray)
        {
            //创建省城区
            Provice *Model = [[Provice alloc] initWithDict:Dict];
            [Arr addObject:Model];
        }
        _Provices = [Arr copy];
    }
    return _Provices;
}

@end

//省
@implementation Provice

- (instancetype)initWithDict:(NSDictionary *)Dict
{
    self = [super init];
    if (self)
    {
        [self setValuesForKeysWithDictionary:Dict];
    }
    return self;
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key{};
@end


//城
@implementation City

- (instancetype)initWithDict:(NSDictionary *)Dict
{
    self = [super init];
    if (self)
    {
        [self setValuesForKeysWithDictionary:Dict];
    }
    return self;
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key{};
@end

//区
@implementation Area
- (instancetype)initWithDict:(NSDictionary *)Dict
{
    self = [super init];
    if (self)
    {
        [self setValuesForKeysWithDictionary:Dict];
    }
    return self;
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key{};
@end
